/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.gob.pnp.factories;

import java.sql.*;
import javax.naming.*;
import javax.sql.*;

/**
 *
 * @author Javero
 */
public class ConnectionPool {

    public static Connection obtenerConexionTramite() throws SQLException {
        Connection conn = null;
        try {
            Context contexto = new InitialContext();
            DataSource fuente = (DataSource) contexto.lookup("java:comp/env/jdbc/tramite");
            conn = fuente.getConnection();
        } catch (Exception ex) {
            throw new SQLException(ex);
        }
        return conn;
    }

    public static Connection obtenerConexion() throws SQLException {
        Connection conn = null;
        try {
            Context contexto = new InitialContext();
            DataSource fuente = (DataSource) contexto.lookup("java:comp/env/jdbc/oracle2");
            conn = fuente.getConnection();
        } catch (Exception ex) {
            throw new SQLException(ex);
        }
        return conn;
    }

    public static void liberarConexion(Connection conn) throws SQLException {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException ex) {
            throw new SQLException(ex);
        }
    }
}
